"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

const _http = require('http');
const URL = require('url');

function http(method, url, data) {
	const _url = URL.parse(url);
	return new Promise((resolve, reject) => {
		const req = _http.request({
			method,
			protocol: _url.protocol,
			host: _url.host,
			port: _url.port,
			path: _url.path,
			// hostname: string;
			// family?: number;
			// port?: number | string;
			// defaultPort?: number | string;
			// localAddress?: string;
			// socketPath?: string;
		}, (rs) => {
			let buf = '';
			rs.on('data', (chunk) => {
				buf += chunk;
			});
			rs.on('end', () => {
				resolve(JSON.parse(buf));
			});
		});
		if (data) {
			req.write(JSON.stringify(data));
		}
		req.end();
		req.on('error', (e) => {
			reject(e);
		});
	});

}

exports.default = http;
